#ifndef THREE_H_INCLUDED
#define THREE_H_INCLUDED

#include "header.h"

#define    SIZE_ARRAY   10
using namespace std;

int MaxSumOfSonArray(int * , int );

bool  done_maxofsubarray = true;

void TestThree()
{
    int array[SIZE_ARRAY];
    cout << "Please input " << SIZE_ARRAY << "numbers into the array:" << endl;

    int i ;
    for (i = 0; i < SIZE_ARRAY; i++)
        cin >> array[i];

    int sum = MaxSumOfSonArray(array, SIZE_ARRAY);
    if (done_maxofsubarray)
        cout << "the max sum of sub array is " << sum << endl;
    else
        cout << "returned error " << endl;

}

int MaxSumOfSonArray(int * array, int length)
{
    if (NULL == array || length < 1) {
        done_maxofsubarray = false;
        return 0;
    }

    int nCurSum = 0;
    int greatSum = 0;
    int i ;

    for (i = 0; i < length; i++) {
        if (nCurSum <= 0)
            nCurSum = array[i];
        else
            nCurSum += array[i];

        if (greatSum < nCurSum )
            greatSum = nCurSum;
    }
    return greatSum;
}


#endif // THREE_H_INCLUDED
